package com.linkhub.oms.dao.mpservice.impl;

import com.linkhub.oms.entity.CompanyEntity;
import com.linkhub.oms.dao.mapper.CompanyEntityMapper;
import com.linkhub.oms.dao.mpservice.ICompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 商家公司表 服务实现类
 * </p>
 *
 * @author echo
 * @since 2024-05-16
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyEntityMapper, CompanyEntity> implements ICompanyService {

    @Override
    public List<CompanyEntity> listByUserId(String userId) {

        return lambdaQuery()
                .eq(CompanyEntity::getUserId, userId)
                .list();
    }

    @Override
    public CompanyEntity getByUserId(String userId) {
        return lambdaQuery()
                .eq(CompanyEntity::getUserId, userId)
                .last("LIMIT 1")
                .one();
    }

    @Override
    public boolean exist(String userId, Long id, String companyName) {
        return lambdaQuery()
                .eq(CompanyEntity::getUserId, userId)
                .ne(Objects.nonNull(id), CompanyEntity::getId, id)
                .eq(CompanyEntity::getCompanyName, companyName)
                .exists();
    }
}
